package com.project.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.project.entity.BookInfo;
import com.project.entity.BookType;
import com.project.service.BookInfoService;
import com.project.service.BookTypeService;

/**
 * 
 * @author beryll@synnex.com
 * 
 */
@Controller
@RequestMapping(value = "/bookquery")
public class BookQueryController {

	@Resource(name = "bookTypeService")
	private BookTypeService btypeService;

	@Resource(name = "bookInfoService")
	private BookInfoService bookService;

	@RequestMapping(value = "/borrowquery")
	public String query(Model model) {
		List<BookType> list = btypeService.listAll();
		model.addAttribute("btypeList", list);
		return "bookquery/borrowquery";
	}

	@RequestMapping(value = "/booklist")
	@ResponseBody
	public Map<String, Object> booklist(@RequestBody Map map, Model model) {
		List<BookInfo> bf = bookService.getBookList(map.get("queryParams"));
		List<Integer> availQuan = bookService.availableQuan(map.get(
				"queryParams").toString());
		Map<String, Object> bfMap = new HashMap<String, Object>();
		bfMap.put("bf", bf);
		bfMap.put("availQuan", availQuan);
		return bfMap;
	}

}
